<cfparam default="none" name="url.api" />

<!---Need to call BASE functions--->
<cfset BASE = CreateObject("component", "#session.rootDir#.cfc.base") />
<cfset baseQueries = CreateObject("component", "#session.rootDir#.cfc.queries") />
<cfset step1Queries = CreateObject("component", "#session.rootDir#.cfc.step1Queries") />
<cfset step2Queries = CreateObject("component", "#session.rootDir#.cfc.step2Queries") />
<cfset nonSCFStep1Queries = CreateObject("component", "#session.rootDir#.cfc.nonSCFStep1-RequestQueries") />

<cfoutput>


    <!--- API INSERTS NONSCF step1 hire.  Function: funcStep1InsertEmployee --->
	<cfif url.api eq "insert_nonscf_step1_employee" >    
	    <cfswitch expression="#CGI.REQUEST_METHOD#">
	        <cfcase value="POST" >
	            
	            <cfset step1Employee = nonSCFStep1Queries.funcStep1InsertEmployee(FORM) />
	            
	            <!---Scott's old code--->
	            <cfset Session.EmpConfirm = "The requests for account and badge for " & FORM.First>
	            <cfif FORM.PreferredName NEQ "">
	                <cfset Session.EmpConfirm = Session.EmpConfirm & " (" & FORM.PreferredName & ")">
	            </cfif>
	            <cfif FORM.Middle NEQ "">
	                <cfset Session.EmpConfirm = Session.EmpConfirm & " " & FORM.Middle>
	            </cfif>
	            <cfset Session.EmpConfirm = Session.EmpConfirm & " " & FORM.Last & 
	            " has been successfully submitted to HR.  Please wait for confirmation of offer acceptance and estimated start date.  Thank you for using E-PAR.
	            <p>Hire another employee?  Click <a href=""Step1-Hire.cfm"">Here</a>">
	            <!---Scott's old code--->
	            
	            <cflocation url="../Step1-Confirmation.cfm" addtoken="no" />
	            
	        </cfcase>    
	    </cfswitch>
	</cfif>
	<!--- API INSERTS NONSCF step1 hire.  Function: funcStep1InsertEmployee --->

   
	
	    
    
	
	<!--- API Updates and Inserts NON SCF step2 pre orientation.  Function: funcUpdateStep2Employee --->
	<cfif url.api eq "update_nonscf_step2_employee" >    
	    <cfswitch expression="#CGI.REQUEST_METHOD#">
	        <cfcase value="POST" >
	            
	            <cfset step2QueriesNSCF = CreateObject("component", "#session.rootDir#.cfc.nonSCFStep2-OrientationQueries") />
	            
	            <cfset step2Employee = step2QueriesNSCF.funcUpdateStep2Employee(FORM) />
	            
	            <cflocation url="Step3-SpawnCreation.cfm?StepID=#step2Employee.NewStepID#" addtoken="no" />
	            
	        </cfcase>    
	    </cfswitch>
	</cfif>
	<!--- API Updates and Inserts NON SCF step2 pre orientation.  Function: funcUpdateStep2Employee --->
    
    
    


	<!--- API handles step3 orientation  --->
	<cfif url.api eq "step3_orientation" >    
        <cfswitch expression="#CGI.REQUEST_METHOD#">
            <cfcase value="GET" >
            	<cfparam default="-1" name="URL.StepID" />
                
                <cflocation url="Step3-Orientation2.cfm?StepID=#URL.StepID#" addtoken="no" />
            </cfcase>    
        </cfswitch>
    </cfif>
	<!--- API handles step3 orientation  --->
    
    
    
    
    
    
    <!--- API handles step3 orientation no show --->
	<cfif url.api eq "step3_no_show" >    
        <cfswitch expression="#CGI.REQUEST_METHOD#">
            <cfcase value="POST" >
            	<cfparam default="-1" name="URL.StepID" />
                
                <!---scf_UpdateAction #Form.cmbNoShow#, #Session.intUserRosettaID#, 'Orientation No Show' - Scott's old stored procedure--->
                <cfset step3UpdateActionNoShow = baseQueries.funcUpdateAction(URL.StepID, Session.intUserRosettaID, 'Orientation No Show') />
                
                <cflocation url="Step3-Confirmation.cfm?StepID=#URL.StepID#" addtoken="no" />
                
            </cfcase>    
        </cfswitch>
    </cfif>
	<!--- API handles step3 orientation no show --->
	    
	    
	    
	    
	    
    
    <!--- API UPDATES step3 orientation Function: funcUpdateStep2Employee --->
	<cfif url.api eq "update_step3_employee" >    
        <cfswitch expression="#CGI.REQUEST_METHOD#">
            <cfcase value="POST" >
            
            	<!--- TODO: Fix this amateur programmer thingy --->
            	<cfif isDefined('URL.NoShow')  >
            		<cfset FORM.Decline = 1/>
                    <cfset Session.OfferAccepted = False />
                <cfelse>
                	<cfset Session.OfferAccepted = True />
                </cfif>
                
                <cfset Session.Comments = FORM.Notes>

                <cfset step3Employee = CreateObject("component", "#session.rootDir#.cfc.step3Queries").funcUpdateStep3Employee(FORM) />
                
                <cfset Session.EmpID = step3Employee.FORM.EmpID />
                
                <cfset Cleared = BASE.EPLSCheck('#step3Employee.FORM.First#', '#step3Employee.FORM.Last#', '#step3Employee.FORM.SSN#', #step3Employee.FORM.EmpID#) />
                
				<cfif Cleared>
                    
                    <cfif Session.OfferAccepted EQ True >
                		<cflocation url="Step3-Orientation3.cfm?StepID=#step3Employee.FORM.StepID#" addtoken="no">
                    <cfelse>
                    	<cflocation url="Step3-Orientation1.cfm" addtoken="no">
                    </cfif>
                     
                <cfelse>
                
                	<cfset Step3InsertAction = CreateObject("component", "#session.rootDir#.cfc.queries").funcInsertAction(step3Employee.FORM.EmpID, 16) />
					<cfset StepID =  Step3InsertAction.NewStepID>
                    <cfset Session.NotCleared = True>
                    <cflocation url="Step3-OrientationEPLSFailed.cfm?StepID=#step3Employee.FORM.StepID#"> 
                      
                </cfif>
                
            </cfcase>    
        </cfswitch>
    </cfif>
	<!--- API UPDATES step3 orientation Function: funcUpdateStep2Employee --->
    
    
    
    
    
    <!--- API Inserts step3 Orientation - Beneficaries Function: funcStep3InsertBeneficaries --->
	<cfif url.api eq "insert_step3_employee_beneficaries" >    
        <cfswitch expression="#CGI.REQUEST_METHOD#">
            <cfcase value="POST" >
                <cfset step3Beneficaries = CreateObject("component", "#session.rootDir#.cfc.step3Queries").funcStep3InsertBeneficaries(FORM) />
            </cfcase>    
        </cfswitch>
    </cfif>
	<!--- API Inserts step3 Orientation - Beneficaries Function: funcStep3InsertBeneficaries --->
    
	    
	    
	    
	    
    
    <!--- API Inserts step3 Orientation - Emergency Contacts Function: funcStep3InsertEmergencyContacts --->
	<cfif url.api eq "insert_step3_emergency_contacts" >    
        <cfswitch expression="#CGI.REQUEST_METHOD#">
            <cfcase value="POST" >
                <cfset step3EmergencyContacts = CreateObject("component", "#session.rootDir#.cfc.step3Queries").funcStep3InsertEmergencyContacts(FORM) />
            </cfcase>    
        </cfswitch>
    </cfif>
	<!--- API Inserts step3 Orientation - Emergency Contacts Function: funcStep3InsertEmergencyContacts --->
    
    
    
    
    
    <!--- API that handles step3 completion Function: funcUpdateAction, funcInsertAction --->
	<cfif url.api eq "step3_completion" >    
        <cfswitch expression="#CGI.REQUEST_METHOD#">
            <cfcase value="POST" >
                <cfset step3Completion = baseQueries.funcUpdateAction(FORM.StepID, Session.intUserRosettaID, 'ee') />
                <cfset step3Completion = baseQueries.funcInsertAction(FORM.EmpID, 4) />
                <!---<cflocation url="Step3-SpawnCreation.cfm?StepID=#step3Completion.NewStepID#" addtoken="no" />--->
            </cfcase>    
        </cfswitch>
    </cfif>
	<!--- API that handles step3 completion Function: funcUpdateAction, funcInsertAction --->
	    
	    
	    
	    
	<!--- API that handles NON SCF Step4 Badge Creation:  --->
	<cfif url.api eq "step4_badge_creation_nonscf" >    
	    <cfswitch expression="#CGI.REQUEST_METHOD#">
	        <cfcase value="POST" >
	            
	            <cfset step4Queries = CreateObject("component", "#session.rootDir#.cfc.step4Queries") />
	            
	            <cfset LOCALS = {} />
	
	            <cfloop index="i" list="#FORM.FieldNames#" DELIMITERS=",">
	                
	                <cfif left(i,5) EQ "Badge">
	
	                    <cfset LOCALS.BadgeNo = Form[i]>
	                    <cfset LOCALS.EmpID = ListGetAt(i, 2, '_')>
	                    <cfset LOCALS.StepID = ListGetAt(i, 3, '_')>
	                    
	                    <cfset QUERIES.GetEmpInfo = baseQueries.funcGetEmpInfo( LOCALS.StepID ) />
	    
	                    <cfif QUERIES.GetEmpInfo.recordcount GT 0>
	                     
	                        <!---Updage Badge Number --->
	                        <cfif isnumeric(LOCALS.BadgeNo) EQ 1>
	                           
	                            <cfset QUERIES.UpdateBadgeNo = step4Queries.funcUpdateBadgeNo(LOCALS.EmpID, LOCALS.BadgeNo ) />
	                            
	                            <cfset QUERIES.UpdateEmployee = step4Queries.funcUpdateEmployee(LOCALS.EmpID, LOCALS.BadgeNo ) />
	                            
	                            <cfset QUERIES.UpdateAction = baseQueries.funcUpdateAction( LOCALS.StepID, Session.intUserRosettaID, 'Batch Style Badge Creation - No Comments' ) />
	                            
	                            <cfset QUERIES.GetAccessRequest = step4Queries.funcGetAccessRequest(LOCALS.EmpID) /> 
	                            
	                            <cfif QUERIES.GetAccessRequest.BadgeAccessLevelID NEQ "-- None --" AND 
	                                QUERIES.GetAccessRequest.BadgeAccessLevelID NEQ 0 AND 
	                                    QUERIES.GetAccessRequest.BadgeAccessLevelID NEQ ""> 
	
	                                <!--- Add to the Facilities Queue only if necessary --->
	                                
	                                <cfset QUERIES.InsertAction = baseQueries.funcInsertAction( LOCALS.EmpID, 7 ) />	                                
	                                
	                            </cfif>
	                                                                                                    
	                        </cfif>
	                                                                                    
	                    </cfif>
	                                                                    
	                </cfif>
	                
	            </cfloop>
                                                    
                <cflocation url="../status.cfm" addtoken="no" />
	        
	        </cfcase>    
	    </cfswitch>
	</cfif>
	<!--- API that handles NON SCF Step4 Badge Creation:  --->
	
	
	
	
	
	
	<!--- API that handles NON SCF Step4 Badge Creation:  --->
	<cfif url.api eq "step5_access_control_update_nonscf" >
	    <cfswitch expression="#CGI.REQUEST_METHOD#">
	        <cfcase value="POST" >
	            
	            <cfset step5Queries = CreateObject("component", "#session.rootDir#.cfc.step5Queries") />
	            
	            <cfset LOCALS = {} />
	
	            <cfloop index="i" list="#FORM.FieldNames#" DELIMITERS=",">
	            
	                <cfif left(i,8) EQ "AccessID">
	                                                    
	                    <cfset LOCALS.Ext = right(i,len(i)-8)>
	                    <cfset LOCALS.AccID = Form[i]>
	                    <cfset LOCALS.EmpID = ListGetAt(i, 2, '_')>
	                    <cfset LOCALS.StepID = ListGetAt(i, 3, '_')>
	                    <cfset LOCALS.Comments = Form['Comments' & LOCALS.Ext]>
	                    
	                    <cfset QUERIES.GetEmpInfo = baseQueries.funcGetEmpInfo( LOCALS.StepID ) />
	
	                    <cfif QUERIES.GetEmpInfo.recordcount GT 0>
	                                                                    
	                        <!---Updage Rosetta Stone with Access Control ID --->
	                        <cfif isnumeric( LOCALS.AccID ) EQ 1>
	                            <cfset QUERIES.UpdateAccessID = step5Queries.funcUpdateAccessID( 
	                                LOCALS.EmpID, LOCALS.AccID
	                            ) />
	                        </cfif> 
	                                                                                    
	                        <!--- Advance the Step Action --->
	                        <cfset QUERIES.UpdateAction = baseQueries.funcUpdateAction( LOCALS.StepID, Session.intUserRosettaID, '#LOCALS.Comments#' ) />
	                        
	                    </cfif>
	                </cfif>
	            </cfloop>
	            
                <cflocation url="../status.cfm" addtoken="no" />
                                                    
	        </cfcase>    
	    </cfswitch>
	</cfif>
	<!--- API that handles NON SCF Step4 Badge Creation:  --->


</cfoutput>